package com.bluishoul.bean;

import java.sql.Timestamp;
import java.util.List;

import my.db.QueryHelper;
import my.util.MyStringUtils;

import org.apache.commons.lang.StringUtils;

@SuppressWarnings("serial")
public class Dish extends Pojo {

	public static Dish INSTANCE = new Dish();

	private long shop;
	private String name;
	private String pinyin;
	private float price;
	private String taste;// 口味：酸甜苦辣咸，清淡，重口味...
	private String category;// “八大菜系”：粤菜、川菜、鲁菜、淮扬菜、浙菜、闽菜、湘菜、徽菜
	private String quantity;// 大，中，小份
	private String ingredient;// 食材组成以逗号隔开
	private String img;
	private String description;
	private int status;
	private long user;
	private Timestamp create_time;

	public boolean CanAdmin(User user) {
		return user != null && user.IsSuperior();
	}

	public List<Long> listShopDishes(long shop) {
		String sql = "SELECT id FROM menu_dish WHERE shop=?";
		return QueryHelper.query(Long.class, sql, shop);
	}

	public Dish hasSame() {
		String sql = "SELECT * FROM menu_dish WHERE  name=? && shop=?";
		return QueryHelper.read(Dish.class, sql, name, shop);
	}

	public boolean Update() {
		String sql = "UPDATE menu_dish SET name=?,pinyin=?,price=?,taste=?,category=?,quantity=?,ingredient=?,img=?,description=? WHERE id=?";
		pinyin = MyStringUtils.getPinyin(name);
		return Evict(QueryHelper.update(sql, name, pinyin, price, taste,
				category, quantity, ingredient, img, description, getId()) == 1);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public String getTaste() {
		return taste;
	}

	public void setTaste(String taste) {
		this.taste = taste;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getQuantity() {
		return quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	public String getIngredient() {
		return ingredient;
	}

	public void setIngredient(String ingredient) {
		this.ingredient = ingredient;
	}

	@Override
	protected String TableName() {
		return "menu_dish";
	}

	@Override
	protected boolean IsObjectCachedByID() {
		return true;
	}

	public Timestamp getCreate_time() {
		return create_time;
	}

	public void setCreate_time(Timestamp create_time) {
		this.create_time = create_time;
	}

	public String getPinyin() {
		if (StringUtils.isBlank(pinyin) && StringUtils.isNotBlank(name))
			pinyin = MyStringUtils.getPinyin(name);
		return pinyin;
	}

	public void setPinyin(String pinyin) {
		this.pinyin = pinyin;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public long getShop() {
		return shop;
	}

	public void setShop(long shop) {
		this.shop = shop;
	}

	@Override
	public long Save() {
		return super.Save();
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public long getUser() {
		return user;
	}

	public void setUser(long user) {
		this.user = user;
	}

}
